/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Dec 31, 2009
 * Time: 10:34:18 AM
 * To change this template use File | Settings | File Templates.
 */
import java.util.*;
import org.jdom.Element;

// Referenced classes of package dk.brics.dsd:
//            Rule, InternalSchemaErrorException, Schema, Boolexp,
//            Context, Validator

class IfRule extends Rule
{

    IfRule(Element element, Schema schema)
    {
        Iterator iterator = element.getChildren().iterator();
        do
        {
            if(!iterator.hasNext())
                break;
            Element element1 = (Element)iterator.next();
            if(!Schema.isDSDElement(element1))
                continue;
            exp = Boolexp.parse(element1, schema);
            break;
        } while(true);
        if(exp == null)
            throw new InternalSchemaErrorException();
        contents = new ArrayList();
        do
        {
            if(!iterator.hasNext())
                break;
            Element element2 = (Element)iterator.next();
            if(Schema.isDSDElement(element2))
                contents.add(Rule.parse(element2, schema));
        } while(true);
    }

    void findApplicableRules(Context context, SortedSet sortedset, Set set)
    {
        byte byte0 = exp.evaluate(context);
        if(byte0 == 1)
        {
            for(Iterator iterator = contents.iterator(); iterator.hasNext(); ((Rule)iterator.next()).findApplicableRules(context, sortedset, set));
        } else
        if(byte0 != 2)
            context.v.invalid(context, "indefinite value at conditional rule", exp.toXML(context));
    }

    Boolexp exp;
    List contents;
}
